
 $('	.imgZoomIn').error(function () {   //加载图片 出现404状态时触发
	var pic = window.rootPath + "/img/nopicture.png";
    $(this).attr("src", pic);  //将加载不到的图片 的src属性 修改成默认 图片 ，注意：默认图片必须保证存在，否则 会一直 调用 此函数
});
function initContent1() {
		
	var divBussinessContent = jQuery("#content1");
	var identify = jQuery("#identify").val();
	
	var lng = jQuery("#lng2").val() == '' ? jQuery("#lng").val() :jQuery("#lng2").val();
	var lat = jQuery("#lat2").val() == '' ? jQuery("#lat").val() :jQuery("#lat2").val();
//		alert(lng+'|'+lat);
	divBussinessContent.empty();
	var url = window.rootPath
			+ '/ui/mobileMain/getContent?lng='+lng+'&lat='+lat;
	jQuery.ajax({
		type : 'get',
		url : url,
		data : '',
		dataType : 'json',
		contentType : 'application/json;charset=utf-8',
		success : function(data) {
			if (data.code == 1) {
				var manager = data.manager;
				if(manager.length > 0){
					initManager1(manager);
				}
				var bussinessContent = data.content.bussinessContent;
				divBussinessContent.append(bussinessContent);
				// var tabContent = jQuery("#contenttab");
				// tabContent.table('refresh');

				var divWidth = divBussinessContent.width();
				oldDIVWidth = divWidth;
				var scale = divWidth / 1000;
				jQuery("#content table").removeAttr("width");
				jQuery("#content tr").removeAttr("width");
				jQuery("#content th").removeAttr("width");
				jQuery("#content td").removeAttr("width");
				// 缩放
				jQuery("#content1 img").each(
					function() {
						var oWidth = $(this).width();
						var oHeight = $(this).height();
						if (oHeight != 0) {
							$(this).width(oWidth * scale);
							$(this).height(oHeight * scale);
						} else {
							$(this).width(divWidth * 0.5);
						}
						$(this).prop("href","#ContentPop");
						$(this).prop("data-rel","popup");
						$(this).prop("data-position-to","window");
						$(this).prop("data-transition","fade");
						$(this).bind("click",function() {
							jQuery("#imgbig").prop("src",this.src);
							//jQuery("#ContentPop").popup("open");
						});
				})
			}
		}
	});
};
function initManager1(manager){
	//清空内容
	$("#manager1").empty();
	var contenthtml = '';
	var intNum=0;
	for(var i=0;i< manager.length ;i++){
		intNum++;
		var purl = manager[i].pictureAddress;// 没有上传图片
		if (purl == undefined || purl == "") {
			purl = "img/defaultTipstaff.png";
		}
		purl = window.rootPath + "/" + purl;
		
		if(intNum == 1){
			contenthtml += '<div class="manager-row">';
		}
		contenthtml += '<div class="manager-col">';
		
		//img
		contenthtml+= '<div class="manager-img"><img width="60px" height="60px" src="' + purl +'"/></div>';
		//content
		contenthtml+= '<div class="manager-content">';
		
		contenthtml+= '<div>'+manager[i].name+'</div>';
		
		var contactType = '';
		if(manager[i].contactType){
			contactType = '<a href="tel:'+ manager[i].contactType +'">'+ manager[i].contactType + '</a>';
			
		}
		
		contenthtml+= '<div>'+contactType+'</div>';
		var position = '';
		if(manager[i].position){
			position = manager[i].position;
		}
		contenthtml+= '<div>'+position+'</div>';
		
		contenthtml+= '</div>'
		contenthtml+= '</div>'
		
		if(intNum == 2){
			intNum = 0;
			contenthtml += '</div>';
		}
	}
	if(intNum == 1){
		contenthtml += '</div>';
	}
	$("#manager1").append(contenthtml);

}
(function() {
	var oldDIVWidth;
	var userRight;
	$("body").on("click", ".extendimg", function (){
		jQuery("#avatarbig").prop("src","");
        var id=$(this).attr('id');
        if(id!="bimg"){
        	jQuery("#avatarbig").prop("src",$("#"+id+"_img").attr("src"));
        } else{
        	jQuery("#avatarbig").prop("src",$("#avatar").attr("src"));
        }
        
	});

	//扫一扫
	$("#sweepImg").on('click',function(){
		if(_phoneType=="Android"){
			window.jump.QRCode(); 
		}else if(_phoneType=="Ios"){
			window.webkit.messageHandlers.useQRCode.postMessage({body: 'useQRCode'});
		}else{
			alert('暂时不支持此功能!');
		}
		return false;
	});
	//快捷上报
	$("#quickReport").on('click',function(){
		window.location.href=window.rootPath+'/ui/eventReport?device=mobile&eventType='+$("#roleType").val()+"&identify=";
	});
	//快捷历史
	$("#quickHistory").on('click',function(){
		
		window.location.href=window.rootPath+$("#historyUrl").val();
	});
	//注册
    jQuery('#subtnForRegister').on('click', function () {
    		var url=window.rootPath+'/ui/mobileMain/register'+"?device=mobile&identify="+$("#identify").val();
    		window.location.href = url;
    });
    //标题登录或者注销
    jQuery("#login-unlogin").on('click',function(){
    		if($("#accountName").val()=="Visitors"){//表明未登录
//    			$("#popupLoginSelect").popup("open");
    			var url=window.rootPath+'/ui/login?device=mobile&identify=';
        		window.location.href = url;
		}else{//登录后切换到注销图标
			VisitorsLogin();
		}
    });
    //注销
    function VisitorsLogin(){
    		var name = "Visitors";
		var password ="visitors";
		var smsCode =jQuery("#smsCode").val();
		var identify = jQuery("#identify").val();
		var urladress =jQuery("#url").val();
			var url = window.rootPath + '/ui/login/msubmit';
			jQuery("input").attr("disabled", true);
			jQuery(".login").attr("disabled", true);
			jQuery(".set").attr("disabled", true);
			
			var data = {
				"accountName" : name,
				"password" : sha256_digest(password),
				"smsCode" : smsCode
			}
			jQuery.ajax({
				url : encodeURI(url),
				type : "post",
				dataType : "json",
				data : JSON.stringify(data),
				contentType : "application/json;charset=UTF-8",
				success : function(data) {
					if(_phoneType=="Ios"){
						
						window.webkit.messageHandlers.clearUserInfo.postMessage({body:"clearUserInfo"});
					}else if(_phoneType=="Android"){
			    			window.jump.delUserInfo();
			    		}
					jQuery("input").attr("disabled", false);
					jQuery(".login").attr("disabled", false);
					jQuery(".set").attr("disabled", false);
					$("#accountName").val("Visitors");
					$("#loginImg").attr("src","../img/app/loginIcon.png");
				}
			});
    };
	///用户登录
    jQuery('#subtnForUser').on('click', function () {
		    var name = jQuery("#user").val();
			var password =jQuery("#pwd").val();
			var smsCode =jQuery("#smsCode").val();
			var identify = jQuery("#identify").val();
			var urladress =jQuery("#url").val();
				var url = window.rootPath + '/ui/login/app/msubmit';
				jQuery("input").attr("disabled", true);
				jQuery(".login").attr("disabled", true);
				jQuery(".set").attr("disabled", true);
				
				
				$("#popupWait").popup();
        		$("#popupWait").popup('open');
				/*jQuery('#loadingImage').show();*/
				var data = {
					"accountName" : name,
					"password" : sha256_digest(password),
					"smsCode" : smsCode
				}
				jQuery.ajax({
					url : encodeURI(url),
					type : "post",
					dataType : "json",
					data : JSON.stringify(data),
					contentType : "application/json;charset=UTF-8",
					success : function(data) {
						jQuery("input").attr("disabled", false);
						jQuery(".login").attr("disabled", false);
						jQuery(".set").attr("disabled", false);
						/*jQuery('#loadingImage').hide();*/
						$("#popupWait").popup('close');
						if (data.code == 0) {
							jQuery('#error').html('用户名或密码错误');
							/*createCode();
							jQuery("#loginCode").val('');*/
						} else if (data.code == 1) {
							/*var picture = data.picture;
							localStorage.setItem('picture', picture);
							localStorage.setItem('name', name);
							localStorage.setItem('userId', data.userId);	*/	
							
							location.reload();
						}
						else if (data.code == 3) {
						
							/*message(data.message);*/
						}
						else if(data.code == 99){//验证码失败
							/*jQuery('#error').html(data.message);*/
						}
					}
				});
    });
//    $("body").on("click", ".menu-scd-click", function (){
//        var id=$(this).attr('id');
//        var s=$(this).attr("href");
//        $("#menu-scd").popup("close");
//        if(id=="goTop"){
//        	$('html,body').animate({scrollTop: '0px'}, 1000);return false;
//        }else if(id=="goBottom"){
//        	$('html,body').animate({scrollTop:$(document).height()+'px'},1000);return false;
//        }/*else if(id=="goaAnds"){
//        	$('html,body').animate({scrollTop: '0px'}, 1000);
//        }*/
//	});
//	$("body").on("click", ".menuClick", function (){
//		$("#menu-scd-list").empty();
//		/*alert($(window).height()); //浏览器当前窗口可视区域高度 
//		alert($(document).height()); //浏览器当前窗口文档的高度 
//		alert($(document.body).height());//浏览器当前窗口文档body的高度 
//		alert($(document.body).outerHeight(true));*/
//		var id=$(this).attr("id");
//		if(id=="menu-login"){
//			$("#popupLoginSelect").popup("open");
//		}else{
//			if(id=="menu-home"){
////				var contenthtml='<li class="ui-li-icon ui-corner-none" data-icon="false"><a href="#pagetwo" data-transition="slide" id="goaAnds">评价</a></li>'
//				var contenthtml=''
//				+'<li class="ui-li-icon ui-corner-none" data-icon="false"><a href="#" class="menu-scd-click" id="goTop">返回顶部</a></li>'
//				+'<li class="ui-li-icon ui-corner-none" data-icon="false"><a href="#" class="menu-scd-click" id="goBottom">返回底部</a></li>';
//				$("#menu-scd-list").append(contenthtml);
//				$("#menu-scd-list").listview('refresh');
//				}else{
//					var contenthtml="";
//					
//					for(var i=0;i<userRight.length;i++){
//						if(userRight[i].mobile!=undefined&&userRight[i].mobile=="true"&&userRight[i].target!="#"&&userRight[i].parentId==id){
//							var url='javascript: ;';
//							var isGo=false;
//							var menuType="menuClick";
//							var icon="home";
//							var dataajax ='';
//							if(userRight[i].icon!=undefined&&userRight[i].icon!=""){
//								icon=userRight[i].icon;
//							}
//							if(userRight[i].target.indexOf("?") != -1){
//								url=window.rootPath+userRight[i].target+"&device=mobile&identify="+$("#identify").val();
//							}else{
//								url=window.rootPath+userRight[i].target+"?device=mobile&identify="+$("#identify").val();
//							}
//						    isGo=true;
//						    menuType="menu-scd-click-bak";
//						    dataajax ='data-ajax="false"';
//							    
//						 contenthtml +='<li class="ui-li-icon ui-corner-none" data-icon="false"><a href="'+url+'" data-icon="'+icon+'" class="'+menuType+'" id="'+userRight[i].id+'" '+dataajax+'>'+userRight[i].moduleName+'</a></li>';
//						}
//					}
//					if(contenthtml!=""){
//						$("#menu-scd-list").append(contenthtml);
//						$("#menu-scd-list").listview('refresh');
//					}
//				}
//				
//				/*var id=$(this).attr("id");*/
//				openGroupMenu(id,"menu-scd","menu-scd-arrow");
//		}
//		});
//	/*计算菜单位置*/
//	function openGroupMenu(controller,controllerscd,controllerscdarrow){
//	    var left, top;
//	    var rect = document.getElementById(controller).getBoundingClientRect();//controller.getBoundingClientRect();
//	    var winrect =document.getElementById(controllerscd).getBoundingClientRect();//controllerscd.getBoundingClientRect();
//	    left = rect.left+ winrect.width/2;
//	    top = rect.top-winrect.height/2+$(document).scrollTop();
//	    $("#"+controllerscd).popup("open", {
//	                x:left,
//	                y:top});
//	    /*计算三角型的位置*/
//	    winrect =document.getElementById(controllerscd).getBoundingClientRect();
//	    document.getElementById(controllerscdarrow).style.left = (rect.left + rect.width/2 - winrect.left) + "px";
//	};
	
	$(document).ready(function() {
		
		if($("#accountName").val()=="Visitors"){//表明未登录
			$("#loginImg").attr("src","../img/app/loginIcon.png");
		}else{//登录后切换到注销图标
			$("#loginImg").attr("src","../img/app/logoutIcon.png");
		}
		
//		$("#btitle").css("background-image","url(../img/白云.jpg)");
		$("#btitle").css("background-image","url(../img/app/banner.png)");
		//$("#btitle").table("refresh");
//		 getData();
		//获取地址
		GetYourLocation();
		 //GetYourLocationByTD();
		 //GetLocationWithHTMLAPI();
		//上报事件
		initEvents();
		//历史新闻
		initNews();
//		var lat = 29.518466591835022;
//		var lng = 106.5151816606521;
//		setLocationIndex(lat,lng);
	});


	/**
	 * 初始化-历史已完结的上报事件信息
	 */
	function initEvents() {
		$.ajax({
			url : window.rootPath + '/ui/mobileMain/getListEvents',
			dataType : 'json',
			type : 'get',
			success : function(result) {

				var events = result.events;
				if (result.code == 1) {
					buildEvents(events, "#events");
				}
			}
		});
	};
	function buildEvents(pageInfo, str) {
		if (pageInfo.length == 0) {
			var contenthtml = '<li><h2 style="color:blue">暂无上报信息</h2></li>';
			$(str).append(contenthtml);
			$(str).listview('refresh');
		}
		for (var i = 0; i < pageInfo.length; i++) {
			var purl = pageInfo[i].reportImgAdress;// 没有上传图片

			if (purl == undefined || purl == "") {
				purl = "img/nopicture.png";
			}
			purl = window.rootPath + "/" + purl;
			var contenthtml='<li><a style="background-color:#FFFFFF" href="#detailInspectPanel" data-transition="slide" class="eventClick" defineId="'+pageInfo[i].id+'" id="'+pageInfo[i].id+'">'
			+ '<div class="listViewImg">'
			+ '<img id="'+pageInfo[i].id+'_img" src="'+purl+'"/>'	
			+ '</div>'
			+ '<div class="listViewContent">'
			+ '<P class="listViewTitle">'+pageInfo[i].reportEventType.eventName+'</p>'
			+ '<p class="listViewMemo">'+pageInfo[i].reportContent+'</p>'
			+ '</div>';
			contenthtml+='</a></li>';
			$(str).append(contenthtml);
		}
		$(str).listview('refresh');
		for(var i=0;i<pageInfo.length;i++){
			$("#"+pageInfo[i].id).removeClass("ui-btn-icon-right");
		}
	}
	
	function buildComments(pageInfo, str) {
		$(str).empty();
		if (pageInfo.length == 0) {
			var contenthtml = '<li><h2 style="color:blue">暂无评论信息</h2></li>';
			$(str).append(contenthtml);
			$(str).listview('refresh');
		}
		for (var i = 0; i < pageInfo.length; i++) {
			var contenthtml = '<div style="margin:auto;margin-bottom: 2px;"><div class="div1"><div width="100%" style="height: 20px;margin-right: 15px;"><div class="box1" style="font-size: 12px;">评论人:'+pageInfo[i].commentator.name+'</div>'
				+ '<div class="box2" style="font-size: 12px;">'+moment(pageInfo[i].createTime).format('YYYY-MM-DD HH:mm')+'</div></div>'
				+ '<div class="div-type">'+pageInfo[i].content+'</div></div></div>';
			$(str).append(contenthtml);
		}
		$(str).listview('refresh');
	}
	
	/**
	 * 上报事件详情页面
	 */
	$("body").on("click",".eventClick",function() {
		// 初始化面板信息
		var reportId = $(this).attr("defineId");// 自定义的属性,方便id的传递
		
		$('#starEventDiv').raty();
		$('#starEventDiv').raty({
			number : 5,
			score : 5,
			targetType: 'hint',
			targetKeep: true,
			size:$("#starEventDiv").attr("width")-5,
			cancel : false
		});
		
		$.ajax({
				url : window.rootPath+'/ui/mobileMain/findReportById/'+ reportId,
				dataType : 'json',
				type : 'get',
				success : function(data) {
					var report = data.report;
					$('#reportId').val(report.id);
					$("#reportAccTime").text(moment(report.reportAccTime).format('YYYY-MM-DD HH:mm'));
					$("#reportUser").text(report.reportUser.name);
					$("#reportMemo").text(report.reportMemo);
					$("#reportContent").text(report.reportContent);
					$("#reportEventType").text(report.reportEventType.eventName);
					
					var reportPic = report.reportImgAdress;
					if (reportPic == undefined || reportPic == "") {
						reportPic = "img/nopicture.png";
					}
					reportPic = window.rootPath + "/" + reportPic;
					$("#reportPic").attr('src',reportPic);
					
					var archive = data.archive;
					$("#archeveDate").text(moment(archive.archeveDate).format('YYYY-MM-DD HH:mm'));
					$("#archiver").text(archive.archiver.name);
					$("#archiveMemo").text(archive.memo);
					$("#archiveContent").text(archive.content);
					
//					var archevePic = archive.photourl;
//					if (archevePic == undefined || archevePic == "") {
//						archevePic = "img/nopicture.png";
//					}
//					archevePic = window.rootPath + "/" + archevePic;
//					$("#archevePic").attr('src',archevePic);
					var archiveInfos = data.archiveInfos;
					setArchevePic(archiveInfos);
					
					
					var comments = data.comments;
					buildComments(comments,"#comments");
					$("#commentContent").text('');
				}
		});
		$(this).prop("href", "#eventPage");
	})
	
	function setArchevePic(data){
		var html ="";
		if(data){
			for(var i=0;i<data.length;i++){
				var archevePic = data[i].photourl;
				if (archevePic == undefined || archevePic == "") {
					archevePic = "img/nopicture.png";
				}
				archevePic = window.rootPath + "/" + archevePic;
				
				html += '<tr><td colspan="2"><img src="'+archevePic+'" class="imgZoomIn" style="width: 100%; height: auto;"/></td>';
			}
		}
		$('#archeveInfos').html(html);
	}
	
	/**
	 * 事件评论
	 */
	jQuery('#saveBtnComment').on('click',function() {
		var content = jQuery('#commentContent').val();
		if(content.trim() == ''){
			alert('请填写评论内容！');
			return false;
		}
		var temp = $('#starEventDiv').raty('score');
		if (temp == undefined) {
			temp = 0;
		}
		var rid = $('#reportId').val();
		
		var url = window.rootPath + '/ui/mobileMain/saveComment';
		var	d = {
			"id"	 : '',
			"eventReport" : {'id':rid},
			"content" : content,
			"score" : temp
		};
		jQuery.ajax({
			url : encodeURI(url),
			type : "post",
			dataType : "json",
			data : JSON.stringify(d),
			contentType : "application/json;charset=UTF-8",
			success : function(data) {
				Alert('评分成功！');
			}
		});
		
	});
	
	
	/**
	 * 初始化-历史新闻
	 */
	function initNews() {
		$.ajax({
			url : window.rootPath + '/ui/mobileMain/getListNews',
			dataType : 'json',
			type : 'get',
			success : function(result) {
				
				var news = result.news;
				
				if (result.code == 1) {
					buildNews(news, "#news");
				}
			}
		});
	};
	function buildNews(pageInfo, str) {
		if (pageInfo.length == 0) {
			var contenthtml = '<li><h2 style="color:blue">暂无新闻信息</h2></li>';
			$(str).append(contenthtml);
			$(str).listview('refresh');
		}
		for (var i = 0; i < pageInfo.length; i++) {
			var purl = pageInfo[i].newsPicture;

			if (purl == undefined || purl == "") {
				purl = "img/nopicture.png";
			}
			purl = window.rootPath + "/" + purl;
			var contenthtml='<li><a style="background-color:#FFFFFF;" href="#newsPanel" data-transition="slide" class="newsClick" defineId="'+pageInfo[i].id+'" id="'+pageInfo[i].id+'">'
			+ '<div class="listViewImg">'
			+ '<img src="'+purl+'"/>'
			+ '</div>'
			+ '<div class="listViewContent">'
			+ '<P class="listViewTitle">'+pageInfo[i].newsTitle+'</p>'
			+ '<p class="listViewMemo">'+pageInfo[i].newsDescribe+'</p>'
			+ '</div>';
			contenthtml+='</a></li>';
			$(str).append(contenthtml);
		}
		$(str).listview('refresh');
		for(var i=0;i<pageInfo.length;i++){
			$("#"+pageInfo[i].id).removeClass("ui-btn-icon-right");
		}
	}
	
	/**
	 * 新闻详情页面
	 */
	$("body").on("click",".newsClick",function() {
		// 初始化面板信息
		var newsId = $(this).attr("defineId");// 自定义的属性,方便id的传递
		
		var newsContent = jQuery("#newsContent");
		
		newsContent.empty();
		
		$.ajax({
			url : window.rootPath+'/ui/mobileMain/findNewsById/'+ newsId,
			dataType : 'json',
			type : 'get',
			success : function(data) {
				$("#createTime").text(moment(data.news.createTime).format('YYYY-MM-DD HH:mm'));
				$("#newsTitle").text(data.news.newsTitle);
				$("#newsUser").text(data.news.user.name);
				$("#newsDescribe").text(data.news.newsDescribe);
				
				newsContent.append(data.news.newsContent);
				// var tabContent = jQuery("#contenttab");
				// tabContent.table('refresh');

				var divWidth = newsContent.width();
				oldDIVWidth = divWidth;
				var scale = divWidth / 1000;
				jQuery("#newsContent table").removeAttr("width");
				jQuery("#newsContent tr").removeAttr("width");
				jQuery("#newsContent th").removeAttr("width");
				jQuery("#newsContent td").removeAttr("width");
				// 缩放
				jQuery("#newsContent img").each(
						function() {
							var oWidth = $(this).width();
							var oHeight = $(this).height();
							if (oHeight != 0) {
								$(this).width(oWidth * scale);
								$(this).height(oHeight * scale);
							} else {
								$(this).width(divWidth * 0.5);
							}
							$(this).prop("href","#ContentPop");
							$(this).prop("data-rel","popup");
							$(this).prop("data-position-to","window");
							$(this).prop("data-transition","fade");
							$(this).bind("click",function() {
								jQuery("#imgbig").prop("src",this.src);
								//jQuery("#ContentPop").popup("open");
							});
						})
				
			}
		});
		$(this).prop("href", "#newsPage");
	})
	
	/**
	 * 初始化数据-页面菜单
	 */
	function getData() {

		var url = window.rootPath + '/ui/mobileMain/getData';
		jQuery.ajax({
			url : encodeURI(url),
			cache : false,
			type : "get",
			data : "",
			dataType : "json",
			contentType : 'application/json;charset=utf-8',// 解决返回数据中的中文乱码问题
			success : function(data) {
				//#动态添加菜单
				var contenthtml='<ul id="menu-list">'
				    +'<li><a href="javascript: ;" data-icon="home" class="menuClick"'
					+'id="menu-home">首页</a></li>'
					+'<li><a href="javascript: ;" data-icon="user" class="menuClick"'
					+'id="menu-login">登录</a></li>';
				userRight =data.modules;
				for(var i=0;i<data.modules.length;i++){
					if(data.modules[i].mobile!=undefined&&data.modules[i].mobile=="true"&&data.modules[i].menuLevel==1){//&&data.modules[i].menuLevel==1
						var url='javascript: ;';
						var isGo=false;
						var menuType="menuClick";
						var icon="home";
						var dataajax ='';
						if(data.modules[i].icon!=undefined&&data.modules[i].icon!=""){
							icon=data.modules[i].icon;
						}
						
						if(data.modules[i].target!="#"){
							if(udata.modules[i].target.indexOf("?") != -1){
								url=window.rootPath+data.modules[i].target+"&device=mobile&identify="+$("#identify").val();
							}else{
								url=window.rootPath+data.modules[i].target+"?device=mobile&identify="+$("#identify").val();
							}
						    isGo=true;
						    menuType="menu-scd-click-bak";
						    dataajax ='data-ajax="false"';
						}
						 contenthtml +='<li><a href="'+url+'" data-icon="'+icon+'" class="'+menuType+'" id="'+data.modules[i].id+'" '+dataajax+'>'+data.modules[i].moduleName+'</a></li>';
					}
				}
				 contenthtml+='</ul>';
				 $('#menu-bar').empty();
				 $('#menu-bar').append(contenthtml);
				 $('#menu-bar').navbar('refresh');
			}
		})
	};
	
	
	$("#file_upload").change(function () {
		/*alert(1);*/
	    var $file = $(this);
	    var fileObj = $file[0];
	    var windowURL = window.URL || window.webkitURL;
	    var dataURL;
	    var $img = $("#avatart");

	    if (fileObj && fileObj.files && fileObj.files[0]) {
	        dataURL = windowURL.createObjectURL(fileObj.files[0]);
	        $img.attr('src', dataURL);
	    } else {
	        dataURL = $file.val();
	        var imgObj = document.getElementById("preview");
	        // 两个坑:
	        // 1、在设置filter属性时，元素必须已经存在在DOM树中，动态创建的Node，也需要在设置属性前加入到DOM中，先设置属性在加入，无效；
	        // 2、src属性需要像下面的方式添加，上面的两种方式添加，无效；
	        imgObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
	        imgObj.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = dataURL;

	    }
	});
	
	jQuery('#fileclick').on('click', function () {
		return  $("#file_upload").click();
	});
	
	/**
	 * 初始化区域新闻信息
	 */
	function initContent() {
		var divBussinessContent = jQuery("#content");
		var identify = jQuery("#identify").val();
		
		var lng = jQuery("#lng2").val() == '' ? jQuery("#lng").val() :jQuery("#lng2").val();
		var lat = jQuery("#lat2").val() == '' ? jQuery("#lat").val() :jQuery("#lat2").val();
		divBussinessContent.empty();
		var url = window.rootPath
				+ '/ui/mobileMain/getContent?lng='+lng+'&lat='+lat;
		jQuery.ajax({
			type : 'get',
			url : url,
			data : '',
			dataType : 'json',
			contentType : 'application/json;charset=utf-8',
			success : function(data) {
				var manager = data.manager;
				if(manager.length > 0){
					initManager(manager);
				}
				if (data.code == 1) {
					var bussinessContent = data.content.bussinessContent;
					divBussinessContent.append(bussinessContent);
					// var tabContent = jQuery("#contenttab");
					// tabContent.table('refresh');

					var divWidth = divBussinessContent.width();
					oldDIVWidth = divWidth;
					var scale = divWidth / 1000;
					jQuery("#content table").removeAttr("width");
					jQuery("#content tr").removeAttr("width");
					jQuery("#content th").removeAttr("width");
					jQuery("#content td").removeAttr("width");
					// 缩放
					jQuery("#content img").each(
						function() {
							var oWidth = $(this).width();
							var oHeight = $(this).height();
							if (oHeight != 0) {
								$(this).width(oWidth * scale);
								$(this).height(oHeight * scale);
							} else {
								$(this).width(divWidth * 0.5);
							}
							$(this).prop("href","#ContentPop");
							$(this).prop("data-rel","popup");
							$(this).prop("data-position-to","window");
							$(this).prop("data-transition","fade");
							$(this).bind("click",function() {
								jQuery("#imgbig").prop("src",this.src);
								//jQuery("#ContentPop").popup("open");
							});
					})
				}
			}
		});
	};
	
	/**
	 * 初始化区域新闻信息
	 */
	function initContentForAndroid() {
		var divBussinessContent = jQuery("#content");
		var identify = jQuery("#identify").val();
		
		var lng = jQuery("#lng2").val();
		var lat = jQuery("#lat2").val();
		divBussinessContent.empty();
		var url = window.rootPath
		+ '/ui/mobileMain/getContent?lng='+lng+'&lat='+lat;
		jQuery.ajax({
			type : 'get',
			url : url,
			data : '',
			dataType : 'json',
			contentType : 'application/json;charset=utf-8',
			success : function(data) {
				
				if (data.code == 1) {
					var manager = data.manager;
					if(manager.length > 0){
						initManager(manager);
					}
					var bussinessContent = data.content.bussinessContent;
					divBussinessContent.append(bussinessContent);
					// var tabContent = jQuery("#contenttab");
					// tabContent.table('refresh');
					
					var divWidth = divBussinessContent.width();
					oldDIVWidth = divWidth;
					var scale = divWidth / 1000;
					jQuery("#content table").removeAttr("width");
					jQuery("#content tr").removeAttr("width");
					jQuery("#content th").removeAttr("width");
					jQuery("#content td").removeAttr("width");
					// 缩放
					jQuery("#content img").each(
							function() {
								var oWidth = $(this).width();
								var oHeight = $(this).height();
								if (oHeight != 0) {
									$(this).width(oWidth * scale);
									$(this).height(oHeight * scale);
								} else {
									$(this).width(divWidth * 0.5);
								}
								$(this).prop("href","#ContentPop");
								$(this).prop("data-rel","popup");
								$(this).prop("data-position-to","window");
								$(this).prop("data-transition","fade");
								$(this).bind("click",function() {
									jQuery("#imgbig").prop("src",this.src);
									//jQuery("#ContentPop").popup("open");
								});
							})
				}
			}
		});
	};

	/**
	 * 获取当前地址坐标
	 */
	function currentLocation(location) {
       //alert(location.coords.longitude+":"+location.coords.latitude);
		 $("#lng").val(location.coords.longitude);
         $("#lat").val(location.coords.latitude);
         //initContent();
         //alert(location.coords.longitude+":"+location.coords.latitude);
      }
	function locationError(error) {
        //error occurred so stop watchPosition
        if( navigator.geolocation ) {
          //navigator.geolocation.clearWatch(watchId);
        }
        switch (error.code) {
          case error.PERMISSION_DENIED:
            alert("Location not provided");
            break;

          case error.POSITION_UNAVAILABLE:
            alert("Current location not available");
            break;

          case error.TIMEOUT:
            alert("Timeout");
            break;

          default:
            alert("unknown error");
            break;
        }
      }
	function showLocation(location) {
        /*//zoom to the users location and add a graphic
        var pt = new Point(location.coords.longitude, location.coords.latitude);
        if ( !graphic ) {
          addGraphic(pt);
        } else { // move the graphic if it already exists
          graphic.setGeometry(pt);
        }
        map.centerAt(pt);*/
      }
	function GetLocationWithHTMLAPI(){
		if( navigator.geolocation) {  
            navigator.geolocation.getCurrentPosition(currentLocation, locationError,{
                // 指示浏览器获取高精度的位置，默认为false
            	enableHighAccuracy: true,
                // 指定获取地理位置的超时时间，默认不限时，单位为毫秒
                timeout: 5000,
                // 最长有效期，在重复获取地理位置时，此参数指定多久再次获取位置。
                maximumAge: 3000
            });
            //watchId = navigator.geolocation.watchPosition(showLocation, locationError);//实时定位的方法
          } else {
            alert("Browser doesn't support Geolocation. Visit http://caniuse.com to see browser support for the Geolocation API.");
          }
	};
	function GetYourLocationByTD(){
		//var map=new T.Map('pop');
		 var geolocation = new T.Geolocation(); 
		 
		 geolocation.getCurrentPosition(function(t,i){
			 var tt=t;
			 var ii=i;
			 alert(JSON.stringify(tt));
		 },{enableHighAccuracy: true});
	}
	function GetYourLocation(){
		/*if( navigator.geolocation) {  
            navigator.geolocation.getCurrentPosition(zoomToLocation, locationError,{
                // 指示浏览器获取高精度的位置，默认为false
            	enableHighAccuracy: true,
                // 指定获取地理位置的超时时间，默认不限时，单位为毫秒
                timeout: 5000,
                // 最长有效期，在重复获取地理位置时，此参数指定多久再次获取位置。
                maximumAge: 3000
            });
            //watchId = navigator.geolocation.watchPosition(showLocation, locationError);//实时定位的方法
          } else {
            alert("Browser doesn't support Geolocation. Visit http://caniuse.com to see browser support for the Geolocation API.");
          }*/
	    //创建百度地图控件  
	    var geolocation = new BMap.Geolocation();
	    geolocation.getCurrentPosition(function(r){  
	        if(this.getStatus() == BMAP_STATUS_SUCCESS){
	            //以指定的经度与纬度创建一个坐标点  
	            var pt = new BMap.Point(r.point.lng,r.point.lat);
	            
	            var cj02=bd09togcj02(r.point.lng,r.point.lat);
	            var gps =gcj02towgs84(cj02[0],cj02[1]);
	            
	            $("#lng").val(gps[0]);
	            $("#lat").val(gps[1]);
	            
	            //alert("baidu:"+r.point.lng+":"+r.point.lat);
	            //alert("tan:"+gps[0]+":"+gps[1]);
	            //创建一个地理位置解析器  
//	            var geoc = new BMap.Geocoder();  
//	            geoc.getLocation(pt, function(rs){//解析格式：城市，区县，街道  
//	                var addComp = rs.addressComponents;  
//	                $("#locationDes").html(addComp.city + ", " + addComp.district + ", " + addComp.street+", "+ addComp.streetNumber);  
//	            });   
	            initContent();
	        }       
	    },{enableHighAccuracy: true})//指示浏览器获取高精度的位置，默认false  
	};
	
	
	function initManager(manager){
		//清空内容
		$("#manager").empty();
		var contenthtml = '';
		var intNum=0;
		for(var i=0;i< manager.length ;i++){
			intNum++;
			var purl = manager[i].pictureAddress;// 没有上传图片
			if (purl == undefined || purl == "") {
				purl = "img/defaultTipstaff.png";
			}
			purl = window.rootPath + "/" + purl;
			
			if(intNum == 1){
				contenthtml += '<div class="manager-row">';
			}
			contenthtml += '<div class="manager-col">';
			
			//img
			contenthtml+= '<div class="manager-img"><img width="60px" height="60px" src="' + purl +'"/></div>';
			//content
			contenthtml+= '<div class="manager-content">';
			
			contenthtml+= '<div>'+manager[i].name+'</div>';
			
			var contactType = '';
			if(manager[i].contactType){
				contactType = '<a href="tel:'+ manager[i].contactType +'">'+ manager[i].contactType + '</a>';
				
			}
			
			contenthtml+= '<div>'+contactType+'</div>';
			var position = '';
			if(manager[i].position){
				position = manager[i].position;
			}
			contenthtml+= '<div>'+position+'</div>';
			
			contenthtml+= '</div>'
			contenthtml+= '</div>'
			
			if(intNum == 2){
				intNum = 0;
				contenthtml += '</div>';
			}
		}
		if(intNum == 1){
			contenthtml += '</div>';
		}
		$("#manager").append(contenthtml);

	}
	
	/**
	 * 监听窗体变化 用于改变新闻图片大小比例
	 */
	$(window).resize(function() {
		var divBussinessContent = jQuery("#content");
		var divWidth = divBussinessContent.width();
		var scale = divWidth / oldDIVWidth;
		oldDIVWidth = divWidth;
		// 缩放
		jQuery("#content img").each(function() {
			var oWidth = $(this).width();
			var oHeight = $(this).height();
			if (oWidth != 50 || oHeight != 0) {
				$(this).width(oWidth * scale);
				$(this).height(oHeight * scale);
			}
		})
		
		jQuery("#newsContent img").each(function() {
			var oWidth = $(this).width();
			var oHeight = $(this).height();
			if (oWidth != 50 || oHeight != 0) {
				$(this).width(oWidth * scale);
				$(this).height(oHeight * scale);
			}
		})
	});
	
	
	/**
	 * Alert
	 * 信息提示
	 */
	function Alert(text){
		showAlert(text);
	    setTimeout(hideAlert, 2000);
	}
	function showAlert(text) {  
	    $.mobile.loading("show",{
	    		theme: 'a',
	    		text: text,
	    		html: '',
	    		textVisible: true,
	    		textonly:true
	    	});  
	}  
	function hideAlert() {
	    $.mobile.loading("hide");  
	}
})();